<%= javascript_include_tag "jquery/jquery.form.js" %>
<form enctype="multipart/form-data" method="post" action="/content/upload_file_to_article" id="uploadForm">
   <input type="file" name="file"/>
   <%= submit_tag "上传", :class => "submit" %>
   <span id="uploadOutput"></span>
</form>
<div id="files">

</div>


<script>
	$(document).ready(function(){
		$('#uploadForm').ajaxForm({
        beforeSubmit: function(a,f,o) {
            o.dataType = "html";
            $('#uploadOutput').html('文件上传中,请稍等...');
        },
        success: function(data) {
            $("#files").append("<a class='files' href='#'>" + data + "</a><br/>")
            $('#uploadOutput').html("");
            $("input[name='file']").val("");
        }
    });

    $(".files").live('click', function(){
      var content = $("#message").val();
      var src     = "[img]" + $(this).html() + "[/img]";

      $("#message").val(content + src);
    });
	});
</script>
      
